from langchain.llms import OpenAI
from langchain.agents import load_tools,initialize_agent,AgentType,Tool
from langchain.chat_models import ChatOpenAI
from langchain.agents.react.base import DocstoreExplorer
from langchain.docstore import Wikipedia


llm = OpenAI(
    api_key='hk-mtiquv1000041663a49a34520ad3294132cbce7abf1c2ef3',
    base_url="https://api.openai-hk.com/v1"
)

docstore = DocstoreExplorer(Wikipedia())

tools = [
    Tool(
        name="Search",
        func=docstore.search,
        description="useful for when you need to ask with search"
    ),
    Tool(
        name='Lookup',
        func=docstore.lookup,
        description="useful for when you need to ask with search"
    )
]
agent = initialize_agent(tools,llm,agent=AgentType.REACT_DOCSTORE,verbose=True)
print(agent.run('秦朝建立是在什么时间？'))